package com.qymerge.manage.core.utils;


/**
 * Created by qiuchen on 2015/7/17.
 */
public abstract class ValueUtils {

    public static boolean getBooleanValue(String value) {
        return "true".equals(value);
    }


    public static float getFloatValue(String value) {
        return getFloatValue(value, 0);
    }

    public static float getFloatValue(String value, int dlt) {
        if (value == null) {
            return dlt;
        }
        try {
            return Float.parseFloat(value.trim());
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        return dlt;
    }

    public static long getLongValue(String value) {
        return getLongValue(value, 0);
    }

    public static long getLongValue(String value, long dlt) {
        if (value == null) {
            return dlt;
        }
        try {
            return Long.parseLong(value.trim());
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        return dlt;
    }


    public static int getIntValue(String value) {
        return getIntValue(value, 0);
    }

    public static int getIntValue(String value, int dlt) {
        if (value == null) {
            return dlt;
        }
        try {
            return Integer.parseInt(value.trim());
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        return dlt;
    }

    public static int getSexValue(String value, int dlt) {
        if (value == null) {
            return dlt;
        }
        try {
            return Integer.parseInt(value.trim()) == 1 ? 1 : 2;
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        return dlt;
    }

    public static String getStringValue(String value) {
        return getStringValue(value, "");
    }

    public static String getStringValue(String value, String dlt) {
        if (value != null) {
            return value.trim();
        }
        return dlt;
    }

    public static void main(String[] args) {
        System.out.println(99 / 100);
    }

}
